package org.syh.boyangfighthealthclub.service.impl;

import org.syh.boyangfighthealthclub.dao.IBookDao;
import org.syh.boyangfighthealthclub.dao.impl.BookDaoImpl;
import org.syh.boyangfighthealthclub.entity.Book;
import org.syh.boyangfighthealthclub.service.IBookService;
import org.syh.boyangfighthealthclub.utils.JavaDateConnection;

import java.sql.Connection;
import java.util.List;

/**
 * @Author: Ben
 * @Date: 2021/3/12 11:09
 */
public class BookServiceImpl implements IBookService {
    IBookDao iBookDao=new BookDaoImpl();
    JavaDateConnection javaDateConnection=new JavaDateConnection();
    @Override
    public boolean insertBook(Book book) {
       Book returnBook=iBookDao.selectBookByBookName(javaDateConnection.getConn(),book.getBookName());
       if(returnBook==null){
           boolean judgment=iBookDao.insertBook(javaDateConnection.getConn(),book);
           if (judgment){
               System.out.println("图书添加成功");
               return true;
           }
       }
        System.out.println("图书添加失败");
        return false;
    }

    @Override
    public boolean deleteBook(Integer id) {
        return iBookDao.deleteBook(javaDateConnection.getConn(),id);
    }

    @Override
    public boolean updateBook(Book book) {
        return iBookDao.updateBook(javaDateConnection.getConn(),book);
    }

    @Override
    public List<Book> selectBooks(int pageNumber, int pageSize) {
        return iBookDao.selectBooks(javaDateConnection.getConn(),pageNumber,pageSize);
    }

    @Override
    public int selectBook() {
        return iBookDao.selectBook(javaDateConnection.getConn());
    }

    @Override
    public Book selectBookById(Integer id) {
        return iBookDao.selectBookById(javaDateConnection.getConn(),id);
    }
}
